import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from '@/page/Home'
import About from '@/page/About'
import Message from '@/page/Message'
import MsgDetail from '@/page/MsgDetail'
import News from '@/page/News'
import NewsDetail from '@/page/NewsDetail'

Vue.use(VueRouter)

// 重新封装push replace 方法，消除冗余路径重复提交 控制台警告

const oldPush = VueRouter.prototype.push
const oldReplace = VueRouter.prototype.replace

VueRouter.prototype.push = function(option,resolve,reject){
    if(!resolve && !reject){
        return oldPush.call(this,option).catch(()=>{})
    }else{
        return oldPush.call(this,option,resolve,reject)
    }
}

VueRouter.prototype.replace = function(option,resolve,reject){
    if(!resolve && !reject){
        return oldReplace.call(this,option).catch(()=>{})
    }else{
        return oldReplace.call(this,option,resolve,reject)
    }
}


export default new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/home',
            component: Home,
            children: [
                {
                    path: 'message',
                    component: Message,
                    name: 'message',
                    children: [
                        {
                            path: 'msgdetail',
                            component: MsgDetail,
                            name: 'msgdetail'
                        },
                    ]
                },
                {
                    path:'news',
                    component:News,
                    name:'news',
                    children:[
                        {
                            path:'newsdetail/:content?/:id?',
                            component:NewsDetail,
                            name:'newsdetail'
                        }
                    ]
                },
                {
                    path: '',
                    redirect: 'message'
                }
            ]
        },
        {
            path: '/about',
            component: About,
            name: 'about'
        },
        {
            path: '/',
            redirect: '/home'
        }
    ]
})